package com.vne.skyemart.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import com.vne.skyemart.model.Screen;
import com.vne.skyemart.service.ScreenService;

@Controller
@SessionAttributes
@RequestMapping("/screen")
public class ScreenController {

	@Autowired
	private ScreenService screenService;

	@RequestMapping(value = "/save", method = RequestMethod.POST)
	public ModelAndView saveScreen(@ModelAttribute(" screen") Screen screen,
			BindingResult result) {
		screenService.addScreen(screen);
		return new ModelAndView("redirect:/screen.html");
	}

	@RequestMapping(method = RequestMethod.GET)
	public String listScreen(Model model) {
		model.addAttribute("screen",  screenService.listScreen());

		return "screenList";
	}

	@RequestMapping(value = "/add", method = RequestMethod.GET)
	public ModelAndView addScreen(@ModelAttribute("screen") Screen screen,
			BindingResult result) {
		return new ModelAndView("addScreen");
	}

}